<?php
class User extends AppModel {
    var $name = 'User';
    var $primaryKey = 'id';
    var $displayField = 'username';

    var $actsAs = array('Acl' => array('requester'));

/*   function parentNode() {
       if (!$this->id && empty($this->data)) {
           return null;
       }
       if (isset($this->data['User']['id'])) {
           $groupId = $this->data['User']['id'];
       } else {
               $groupId = $this->field('id');
       }
       if (!$groupId) {
           return null;
       } else {
           return array('Group' => array('id' => $groupId));
       }
    }
*/

	 function parentNode( ) {
                if (!$this->id) {
                        return null;
                }

                $data = $this->read();

                if (!$data['User']['group_id']){
                        return null;
                } else {
                        return array('model' => 'Group', 'foreign_key' => $data['User']['group_id']);
                }
        }	

    /* Obtengo el nombre del grupo al cual pertenece el usuario */
    function getGroup( $auth)
	{	
		$name = $this->Group->findById($auth['User']['group_id']);
        return ($name['Group']['group_name']);
    }

    var $belongsTo = array(
        'Group',
        'Person',
        'Customer'
    );

    function hashPasswords($data) {
       if (isset($data['User']['password'])){
           $data['User']['password'] = md5($data['User']['password']);
           return $data;
       }
       return $data;
    } 
}
?>
